﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BUS;
using DTO;
namespace QLDT
{
    public partial class NhapDiem : DevExpress.XtraEditors.XtraForm
    {

        public DTO_TaiKhoan taikhoan;
        private string ID_PCDT;
        private float DiemNHD;
        private float DiemPB;
        public NhapDiem(DTO_TaiKhoan tk)
        {
            taikhoan = tk;
            InitializeComponent();
        }
        public void createGridlookup()
        {
          
            ////////////////////////////////////////////////////////////////////////////
            //gridLookUpMaKH 
            gridLookUpMaKH.EditValue = null;
            gridLookUpMaKH.Properties.View.OptionsBehavior.AutoPopulateColumns = false;
            gridLookUpMaKH.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            gridLookUpMaKH.Properties.ValueMember = "MaKH";
            gridLookUpMaKH.Properties.DisplayMember = "MaKH";
            gridLookUpMaKH.Properties.View.BestFitColumns();
            gridLookUpMaKH.Properties.PopupFormWidth = 400;
            gridLookUpMaKH.Properties.NullText = "Chọn khóa học";
            gridLookUpMaKH.Properties.DataSource = BUS_KhoaHoc.SelectKhoaHoc();

            // gridLookUpMaLoaiDT
            gridLookUpMaLoaiDT.EditValue = null;
            gridLookUpMaLoaiDT.Properties.View.OptionsBehavior.AutoPopulateColumns = false;
            gridLookUpMaLoaiDT.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            gridLookUpMaLoaiDT.Properties.ValueMember = "MaLoaiDT";
            gridLookUpMaLoaiDT.Properties.DisplayMember = "MaLoaiDT";
            gridLookUpMaLoaiDT.Properties.View.BestFitColumns();
            gridLookUpMaLoaiDT.Properties.PopupFormWidth = 400;
            gridLookUpMaLoaiDT.Properties.NullText = "Chọn loại đề tài";
            gridLookUpMaLoaiDT.Properties.DataSource = BUS_LoaiDT.selectLoaiDeTai();
            //gridLookUpMaLop

            gridLookUpMaLop.EditValue = null;
            gridLookUpMaLop.Properties.View.OptionsBehavior.AutoPopulateColumns = false;
            gridLookUpMaLop.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            gridLookUpMaLop.Properties.ValueMember = "Malop";
            gridLookUpMaLop.Properties.DisplayMember = "Malop";
            gridLookUpMaLop.Properties.View.BestFitColumns();
            gridLookUpMaLop.Properties.PopupFormWidth = 400;
            gridLookUpMaLop.Properties.NullText = "Chọn lớp";
            gridLookUpMaLop.Properties.DataSource = BUS_Lop.SelectLop();

      
        }
        public void loadPCDT()
        {
            string makh = "%";
            string malop = "%";
            string maloaidt = "%";
            bool dalam_danglam = true;
            if (radio_Dalam_Danglam.SelectedIndex == 0)
                dalam_danglam = false;
            else
                dalam_danglam = true;
            if (gridLookUpMaKH.EditValue != null)
                makh = gridLookUpMaKH.EditValue.ToString();
            if (gridLookUpMaLop.EditValue != null)
                malop = gridLookUpMaLop.EditValue.ToString();
            if (gridLookUpMaLoaiDT.EditValue != null)
                maloaidt = gridLookUpMaLoaiDT.EditValue.ToString();
            grid_nhapdiem.DataSource = BUS_PhanCongDT.PCDT_Select_Chamdiem(makh, malop, maloaidt, dalam_danglam);
        
        }
        public void load()
        {
           
            createGridlookup();

        }
        private void simpleBt_NhapDiem_Click(object sender, EventArgs e)
        {

        }

        private void NhapDiem_Load(object sender, EventArgs e)
        {
            load();
            //grid_nhapdiem.DataSource = BUS_QLPhanCongDT.SelectPhanCongDT();
            simpleBt_CapNhat.Enabled = true;
            simpleBt_Huy.Enabled = true;

         
        }

        private void radio_Dalam_Danglam_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadPCDT();
        }
        public void CapNhat()
        {
          //  if (!KTDulieu())
           // {
            //    XtraMessageBox.Show("Nhập đầy đủ nga", "Thông báo");
            //    return;
           // }
            DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();

            //DiemNHD = float.Parse(txt_DiemNHD.Text);
            //DiemPB = float.Parse(txt_DiemPB.Text);
            DiemNHD = float.Parse(gv_nhapdiem.GetRowCellValue(gv_nhapdiem.FocusedRowHandle, "DiemNHD").ToString());
            DiemPB = float.Parse(gv_nhapdiem.GetRowCellValue(gv_nhapdiem.FocusedRowHandle, "DiemPB").ToString());
            ID_PCDT = gv_nhapdiem.GetRowCellValue(gv_nhapdiem.FocusedRowHandle, "ID_PCDT").ToString();
            if (BUS_QLPhanCongDT.UpdateDiem(DiemNHD, DiemPB, ID_PCDT))
            {
                load();
                loadPCDT();
            }
            else
                XtraMessageBox.Show("lỗi từ hệ thống, hãy liên hệ với bộ phận kỹ thuật, mã lỗi [simpleBt_CapNhat_Click]", "Thông báo");

        }
        private void simpleBt_CapNhat_Click(object sender, EventArgs e)
        {
            CapNhat();
        }

        
        private void gridLookUpMaLop_EditValueChanged(object sender, EventArgs e)
        {
            loadPCDT();
        }

        private void gridLookUpMaKH_EditValueChanged(object sender, EventArgs e)
        {
            if (gridLookUpMaKH.EditValue != null)
            {
                string makh = gridLookUpMaKH.EditValue.ToString();
                gridLookUpMaLop.EditValue = null;
                gridLookUpMaLop.Properties.View.OptionsBehavior.AutoPopulateColumns = false;
                gridLookUpMaLop.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
                gridLookUpMaLop.Properties.ValueMember = "Malop";
                gridLookUpMaLop.Properties.DisplayMember = "Malop";
                gridLookUpMaLop.Properties.View.BestFitColumns();
                gridLookUpMaLop.Properties.PopupFormWidth = 400;
                gridLookUpMaLop.Properties.NullText = "Chọn lớp";
                gridLookUpMaLop.Properties.DataSource = BUS_Lop.SelectLop_theoKhoaHoc(makh);
            }
            loadPCDT();
        }

        private void gridLookUpMaLoaiDT_EditValueChanged(object sender, EventArgs e)
        {
            loadPCDT();
        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

     

      
       

     
    }
}